<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fns" uri="http://java.sun.com/jsp/jstl/functionss" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>地锁列表</title>
    <jsp:include page="../../body/link-page.jsp" flush="true"/>

</head>
<body>
<div class="panel">
    <form id="form" action="/car/lock/list" method="post">
    <div class="panel-heading row">
        <div class="col-md-8">
            <button type="button" id="demo-dt-addrow-btn" class="btn btn-info" onclick="LAYER.addLayerWithSize('layer_lockAdd','添加地锁','/car/lock/add','720px','280px')">
                <i class="fa fa-plus"></i> 添加
            </button>
            <button type="button" class="btn btn-success" onclick="toEdit();"><i class="fa fa-edit"></i>修改</button>
            <button type="button" class="btn btn-primary" onclick="deleteAll();"><i class="fa fa-trash-o"></i>删除</button>
        </div>
        <div class="col-md-4">
            <div class="input-group" style="text-align: right">
                <div class="input-group-addon">
                    <span class="fa fa-search"></span>
                </div>
                <input type="text" name="search" id="search" class="form-control col-md-3" placeholder="搜索列表内容"/>
                <div class="input-group-btn">
                    <button type="button" class="btn btn-primary btn-search">搜索</button>
                    <button type="button" class="btn btn-primary btn-reset" style="margin-left: 3px;">重置</button>
                </div>
            </div>
        </div>

    </div>


        <div id="table-box" class="panel-body">

            <table id="table" class="table table-striped table-bordered dataTable no-footer dtr-inline"
                   cellspacing="0" width="100%" role="grid" aria-describedby="demo-dt-addrow_info"
                   style="width: 100%;"
                   data-pn="${lockList.pageNum}" data-ps="${lockList.pageSize}" data-tp="${lockList.totalPage}"
                   data-tr="${lockList.totalRecord}">
                <thead>
                <tr role="row">
                    <th style="width: 20px;"><input type="checkbox" id="check-all"/></th>
                    <th>地锁编号</th>
                    <th>停车场名称</th>
                    <th>地锁开关</th>
                    <th>当前状态</th>
                    <th>绑定状态</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="lock" items="${lockList.results}" varStatus="status">
                    <tr role="row" class="odd">
                        <td><input type="checkbox" value="${lock.id}"/></td>
                        <td>${lock.number}</td>
                        <td>${lock.parkingName}</td>
                        <td>
                            <c:if test="${lock.lockIo == 0}">关闭</c:if>
                            <c:if test="${lock.lockIo == 1}">打开</c:if>
                        </td>
                        <td>
                            <c:if test="${lock.status==0}">空闲</c:if>
                            <c:if test="${lock.status==1}">已预定</c:if>
                            <c:if test="${lock.status==2}">使用中</c:if>
                            <c:if test="${lock.status==3}">电压不足</c:if>
                        </td>
                        <td>
                            <c:if test="${lock.bindingState == 0}">未被绑定</c:if>
                            <c:if test="${lock.bindingState == 1}">已被绑定</c:if>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <ul class="pagination"></ul>
        </div>

    </form>
</div>
</body>
<jsp:include page="../../body/javascript-page.jsp" flush="true"/>
<script type="application/javascript">

    function toEdit(){
        var id = getAllCheck("form");
        if(id.length != 1){
            layer.msg("请选择一条数据",{icon:0,timeout:1000});
        } else {
            LAYER.addLayerWithSize("layer_lockEdit","修改地锁","/car/lock/edit?id="+id,'720px','350px');
        }
    }

    function  deleteAll(){
        var  ids=getAllCheck("form");
        if(ids.length <=0){
            layer.msg("请选择删除的数据",{icon:0,timeout:1000});
        }else{
            layer.confirm("确定要删除" + ids.length + "条数据？",{title:"提示",btn:["确定","取消"]},function () {
                $.ajax({
                    type:"POST",
                    url:"/car/lock/deleteDataByIds",
                    dataType:"json",
                    data:{"ids":ids.join(",")},
                    success:function (data) {
                        if(data.success){
                            layer.msg("删除成功",{icon:1,timeout:1000});
                            reloadPage();
                        } else {
                            layer.msg("删除失败",{icon:2,timeout:1000});
                        }
                    }
                    });
            });
        }
     }
</script>
</html>
